﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using PGMHelper;

namespace BeamRein
{
    public class StructureObj
    {
        /// <summary>
        /// 楼层信息
        /// </summary>
        private List<Storey> storeyList { set; get; }

        /// <summary>
        /// 梁统计
        /// </summary>
        /// <param name="beamEnum"></param>
        /// <returns></returns>
        private GridViewDatas GetTotalData()
        {
            //初始化表格
            var data = new GridViewDatas("楼层总信息");
            //获得楼层求和信息
            var reinList = (from storey in this.storeyList select storey.Reinforce).ToList();
            //获得所有楼层名
            data.Add(new GridViewColumn(this.storeyList.GetPropertyList("Name"), "楼层"));
            //本层面积
            data.Add(new GridViewColumn(this.storeyList.GetPropertyList("Area"), "本层面积"));
            //本层面积
            data.Add(new GridViewColumn(this.storeyList.GetPropertyList("ReinforceArea"), "单方含钢量"));
            //添加数据
            ReinforceInfo.ListToData(data, reinList);
            //返回统计信息
            return data;
        }

        /// <summary>
        /// 梁统计
        /// </summary>
        /// <param name="beamEnum"></param>
        /// <returns></returns>
        private GridViewDatas GetStoreySumData(BeamEnum beamEnum)
        {
            //初始化表格
            var data = new GridViewDatas(beamEnum.ToString() + "用量统计");
            //获得楼层求和信息
            var reinList = (from storey in this.storeyList select storey.GetReinforceInfo(beamEnum)).ToList();
            //获得所有楼层名
            data.Add(new GridViewColumn(this.storeyList.GetPropertyList("Name"), "楼层"));
            //添加数据
            ReinforceInfo.ListToData(data, reinList);
            //返回统计信息
            return data;
        }

        /// <summary>
        /// 生成XLSX
        /// </summary>
        public void ToXLSX()
        {
            //初始化列表
            var dataList = new List<GridViewDatas>();
            //总信息
            dataList.Add(this.GetTotalData());
            //添加统计数据
            for (int i = 0; i < GlobalParam.BeamTypeCount; i++)
                dataList.Add(this.GetStoreySumData((BeamEnum)i));
            //各层信息
            this.storeyList.ForEach(storey => dataList.Add(storey.GetBeamData()));
            //生成xlsx
            NPOI.Helper.NPOIExcelHelper.SaveDatasToExcel(dataList, true);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="directPath"></param>
        public StructureObj(string directPath)
        {
            //实例化
            this.storeyList = new List<Storey>();
            //获得目标文件
            var filePathList = WilsonHelper.GetSpecificFiles(directPath, "层梁钢筋用量统计.txt");
            //遍历构造楼层
            filePathList.ForEach(path => this.storeyList.Add(new Storey(path)));
            //排序
            this.storeyList.OrderBy("StoreyIndex");
        }

    }
}
